#!/bin/bash
#
# $Id: check_dns.sh 147 2011-03-29 09:21:28Z mamartynov@gmail.com $
#

. $OPENARS_HOME/common/debug.h || exit 1
. $OPENARS_HOME/common/functions.h || exit 1

[ -z "$USER_ARS" ] && USER_ARS=$LOGNAME
[ -z "$1" ] && { ERR "need parametr \"filename\""; exit 1; }
[ ! -f "$1" ] && { ERR "not find file \"$1\""; exit 1; }

infile=$TEMPDIR/infile
cat $1 | sed s/#.*$//g | awk 'NF>0 {print}' > $infile
INF "count hosts: `cat $infile | wc -l`"

while read line
do
    (
    ip=`echo $line | awk '{print $1}'`
    host=`echo $line | awk '{print $2}'`
    [ -z "$ip" -o -z "$host" ] && { WARN "not correct line \"$ip:$host\""; continue; }
    /usr/bin/nslookup $host 2>/dev/null | grep " $ip$" >/dev/null
    [ $? -ne 0 ] && ERR "$ip:$host is not correct DNS"
    ) &
done < $infile

WAIT 180

exit 0
